package leetcode_top;

import java.util.*;
import org.junit.*;

public class Ex190 {
    public class Solution {
        Map<Integer, Integer> map = new HashMap<>();

        public int reverseBits(int n) {
            if (map.containsKey(n))
                return map.get(n);
            int d = 0;
            for (int i = 0; i < 32; i++) {
                d |= (n & 1) << (31 - i);
                n >>>= 1;
            }
            map.put(n, d);
            return d;
        }

        // public int myPow(int n) {
        // int x = 2;
        // int res = 1;
        // while (n != 0) {
        // if ((n & 1) == 1) {
        // res *= x;
        // }
        // x *= x;
        // n >>>= 1;
        // }
        // return res;
        // }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        // System.out.println(s.myPow(12));
        System.out.println(s.reverseBits(-3));
        System.out.println(1 << 31);

        synchronized (obj) {
            try {
                this.wait(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
    static Object obj = new Object();

    static class Task implements Runnable {

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName() + "start");
            synchronized (obj) {
                try {
                    obj.wait(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "等待结束");
                Thread.yield();
            }
            System.out.println(Thread.currentThread().getName() + "end");

        }
        
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(new Ex190.Task(), "task1");
        Thread t2 = new Thread(new Ex190.Task(), "task2");

        t1.start();
        t2.start();
    }

    /*
     * select id, number, dense_rank() over(order by number desc) as t_rank from
     * passing_number order by id asc
     */
}
